package com.mywork.activity;

import android.os.Handler;
import android.support.v4.app.Fragment;
import android.support.v4.view.ViewPager;

import com.ciko.code.adapter.TabPagerAdapter;
import com.ciko.code.base.BaseActicity;
import com.ciko.code.fragment.WorkPlaneMyFragment;
import com.ciko.code.fragment.WorkPlaneReceiveFragment;
import com.ciko.code.fragment.WorkPlaneSendFragment;
import com.ciko.code.views.SwingLableBarWeight;
import com.mywork.R;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by 12154 on 2015/11/5.
 */
public class WorkPlaneActivity extends BaseActicity {

    private String[] mTitles = { "我的计划", "收到的计划", "发出的计划" };

    private TabPagerAdapter tabPagerAdapter;

    private List<Fragment> fragmentList = new ArrayList<>();

    private SwingLableBarWeight slb_planeWork;
    private ViewPager vp_contentPlaneWork;

    private Handler workPlanHandler;
    String locationAddress;
    private String title = "";

    WorkPlaneMyFragment  mWorkPlaneMyFragment= new WorkPlaneMyFragment();
    WorkPlaneReceiveFragment  mWorkPlaneReceiveFragment= new WorkPlaneReceiveFragment();
    WorkPlaneSendFragment  mWorkPlaneSendFragment= new WorkPlaneSendFragment();

    public void setWorkPlanHandler(Handler handler){
        workPlanHandler = handler;
    }

    @Override
    protected void initTopBar() {
        if (getIntent().getExtras().containsKey("title")) {
            title = getIntent().getStringExtra("title");
        }
        setTitle(title);
        enableNavLeftImg();
    }

    @Override
    protected void initLayout() {
        setContentView(R.layout.activity_work_plane);
    }

    @Override
    protected void initView() {
        slb_planeWork = findViewByID(R.id.slb_planeWork);
        vp_contentPlaneWork = findViewByID(R.id.vp_contentPlaneWork);
    }

    @Override
    protected void initAdapter() {
        mWorkPlaneMyFragment.setsubmitPlaneCallBack(new WorkPlaneMyFragment.submitPlaneCallBack() {
            @Override
            public void submitOk() {
                mWorkPlaneSendFragment.onResume();
            }
        });
        fragmentList.add(mWorkPlaneMyFragment);

        fragmentList.add(mWorkPlaneReceiveFragment);
        fragmentList.add(mWorkPlaneSendFragment);

        tabPagerAdapter = new TabPagerAdapter(getSupportFragmentManager(), fragmentList, mTitles);
        vp_contentPlaneWork.setAdapter(tabPagerAdapter);
        slb_planeWork.setViewPager(vp_contentPlaneWork);
    }

    @Override
    protected void initDates() {
        locationAddress = getIntent().getStringExtra("address");
        mWorkPlaneMyFragment.setAddress(locationAddress);
    }

    @Override
    protected void initListener() {

    }


//    @Override
//    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
//        super.onActivityResult(requestCode, resultCode, data);
//    }
}
